using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class IpadjustMap : EntityTypeConfiguration<Ipadjust>
    {
        public IpadjustMap()
        {
            // Primary Key
            this.HasKey(t => t.ADJID);

            // Properties
            this.Property(t => t.ITEM)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.LOCATION)
                .IsRequired()
                .HasMaxLength(3);

            this.Property(t => t.TRANSCODE)
                .HasMaxLength(1);

            this.Property(t => t.DESC)
                .HasMaxLength(30);

            this.Property(t => t.ACCT)
                .HasMaxLength(40);

            this.Property(t => t.ADJID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            this.Property(t => t.INVACCT)
                .HasMaxLength(40);

            this.Property(t => t.vglbatch)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Ipadjust");
            this.Property(t => t.ITEM).HasColumnName("ITEM");
            this.Property(t => t.LOCATION).HasColumnName("LOCATION");
            this.Property(t => t.DATE).HasColumnName("DATE");
            this.Property(t => t.QTY).HasColumnName("QTY");
            this.Property(t => t.TRANSCODE).HasColumnName("TRANSCODE");
            this.Property(t => t.DESC).HasColumnName("DESC");
            this.Property(t => t.ACCT).HasColumnName("ACCT");
            this.Property(t => t.PURITY).HasColumnName("PURITY");
            this.Property(t => t.GROSSWGHT).HasColumnName("GROSSWGHT");
            this.Property(t => t.PUREWGHT).HasColumnName("PUREWGHT");
            this.Property(t => t.COST).HasColumnName("COST");
            this.Property(t => t.AMOUNT).HasColumnName("AMOUNT");
            this.Property(t => t.IN_PCS).HasColumnName("IN_PCS");
            this.Property(t => t.GOLDSILV).HasColumnName("GOLDSILV");
            this.Property(t => t.ITEMTYPE).HasColumnName("ITEMTYPE");
            this.Property(t => t.CURRENCY).HasColumnName("CURRENCY");
            this.Property(t => t.POSTED).HasColumnName("POSTED");
            this.Property(t => t.Reference).HasColumnName("Reference");
            this.Property(t => t.ADJID).HasColumnName("ADJID");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.expiryDate).HasColumnName("expiryDate");
            this.Property(t => t.AdjustType).HasColumnName("AdjustType");
            this.Property(t => t.TIME).HasColumnName("TIME");
            this.Property(t => t.CSTCTRID).HasColumnName("CSTCTRID");
            this.Property(t => t.INVACCT).HasColumnName("INVACCT");
            this.Property(t => t.vglbatch).HasColumnName("vglbatch");
            this.Property(t => t.Closed).HasColumnName("Closed");
            this.Property(t => t.AdjHeader).HasColumnName("AdjHeader");
            this.Property(t => t.QTY_Opp).HasColumnName("QTY_Opp");

            // Relationships
            this.HasOptional(t => t.Acct1)
                .WithMany(t => t.Ipadjusts)
                .HasForeignKey(d => d.ACCT);
            this.HasOptional(t => t.Acct2)
                .WithMany(t => t.Ipadjusts1)
                .HasForeignKey(d => d.INVACCT);
            this.HasOptional(t => t.AdjHeader1)
                .WithMany(t => t.Ipadjusts)
                .HasForeignKey(d => d.AdjHeader);
            this.HasOptional(t => t.Cstctr)
                .WithMany(t => t.Ipadjusts)
                .HasForeignKey(d => d.CSTCTRID);
            this.HasRequired(t => t.currency1)
                .WithMany(t => t.Ipadjusts)
                .HasForeignKey(d => d.CURRENCY);
            this.HasOptional(t => t.Ipadjust2)
                .WithMany(t => t.Ipadjust1)
                .HasForeignKey(d => d.Reference);
            this.HasRequired(t => t.IpAdjustType)
                .WithMany(t => t.Ipadjusts)
                .HasForeignKey(d => d.AdjustType);

        }
    }
}
